package com.cskaoyan.market.admin.service.impl;

import org.apache.ibatis.session.SqlSession;

import com.cskaoyan.market.admin.service.MarketAdminDashboardService;
import com.cskaoyan.market.db.domain.MarketGoodsExample;
import com.cskaoyan.market.db.domain.MarketGoodsProductExample;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsProductMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.util.MyBatisUtil;

/**
 * @author BlackFlame33
 * @date 2023/03/19
 **/
public class MarketAdminDashboardServiceImpl implements MarketAdminDashboardService {
    @Override
    public Integer getGoodsTotal() {
        SqlSession session = MyBatisUtil.getSession();
        MarketGoodsMapper mapper = session.getMapper(MarketGoodsMapper.class);
        long result = mapper.countByExample(new MarketGoodsExample());
        return Math.toIntExact(result);
    }

    @Override
    public Integer getUserTotal() {
        SqlSession session = MyBatisUtil.getSession();
        MarketUserMapper mapper = session.getMapper(MarketUserMapper.class);
        long result = mapper.countByExample(new MarketUserExample());
        return Math.toIntExact(result);
    }

    @Override
    public Integer getProductTotal() {
        SqlSession session = MyBatisUtil.getSession();
        MarketGoodsProductMapper mapper = session.getMapper(MarketGoodsProductMapper.class);
        long result = mapper.countByExample(new MarketGoodsProductExample());
        session.commit();
        session.close();
        return Math.toIntExact(result);
    }

    @Override
    public Integer getOrderTotal() {
        SqlSession session = MyBatisUtil.getSession();
        MarketOrderMapper mapper = session.getMapper(MarketOrderMapper.class);
        long result = mapper.countByExample(new MarketOrderExample());
        session.commit();
        session.close();
        return Math.toIntExact(result);
    }
}